﻿using FAS.DAL.Entity;
using FAS.DAL.Utils;
using FAS.WEB.Util;
using System;
using System.Data.SqlClient;
using System.IO;


namespace FAS.WEB.Views
{
    public partial class RestoreDb: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MyUser user = WebUtil.checkLoginUser();
            clearError();
        }
        private void showError(string error)
        {
            errorBottomLabel.Text = errorTopLabel.Text = error;
            workPanel.Visible = false;
        }
        private void clearError()
        {
            errorBottomLabel.Text = errorTopLabel.Text = "";
            workPanel.Visible = true;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!file1.HasFile) return;
            string file = Server.MapPath("~/Download/DbBackup/" + file1.FileName);
            if (File.Exists(file)) File.Delete(file);
            file1.SaveAs(file);
            try
            {
                new DbBackup().restore("FAS", file);
                errorBottomLabel.Text = "数据库恢复成功。<br/>" ;
            }
            catch (Exception error)
            {
                errorBottomLabel.Text = "数据恢复失败。<br/>" + error.Message;
            }
        }
    }
}